package com.xjwlmq.dx.servlet;

import com.alibaba.fastjson.JSON;
import com.xjwlmq.dx.dao.impl.RainQualityImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * @ClassName RainQualityDelViaId
 * @Description TODO:
 * @Author 12994
 * @Date 2024/9/30 16:54
 * @Version 1.0
 **/
@WebServlet("/delViaId")
public class RainQualityDelViaId extends HttpServlet {
    RainQualityImpl rainQuality = new RainQualityImpl();

    @Override
    protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
//        super.service(req, resp);
        resp.setCharacterEncoding("UTF-8");
        resp.setContentType("text/html:charset=UTF-8");

        /*
         * 根据用户ID删除指定
         * req.getParameter();从get url中提取参数
         * Integer.getInteger; 从字符串转Int
         */
        int cont = rainQuality.delRainQualityViaId(Integer.parseInt(req.getParameter("id")));
        if (cont > 0) {
            resp.getWriter().write(JSON.toJSONString("成功删除了%d行数据.".formatted(cont)));
        } else {
            resp.getWriter().write(JSON.toJSONString("没有影响数据..."));
        }
    }
}
